<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Darkangle Flash Avatar Editor Demo</title>
<style>
a{color:#3b5998;}
</style>
</head>
<body style="font-family:'微软雅黑','宋体',verdana;font-size:14px;">
<div style="width:600px;margin:0 auto;padding-top:50px;">
  <div>
    
    <div style="padding:10px 0;color:#666;">
    你最好上传一张真人照片证明你是地球人，也可以  <a style="color:#cc3300;" href="javascript:void(0);" onclick="useCamera()">快使用摄像头，喝喝哈嘿！~</a>
    </div>
    <form enctype="multipart/form-data" method="post" name="upform" target="upload_target" action="<%=request.getContextPath()%>/upload.html">
    <input type="file" name="Filedata" id="Filedata"/>
    <input style="margin-right:20px;" type="submit" name="" value="上传形象照" onclick="return checkFile();" /><span style="visibility:hidden;" id="loading_gif"><img src="loading.gif" align="absmiddle" />上传中，请稍侯......</span>
    </form>
    <iframe src="about:blank" name="upload_target" style="display:none;"></iframe>
    <div id="avatar_editor"></div>
    <script type="text/javascript">
    //允许上传的图片类型
    var extensions = 'jpg,jpeg,gif,png';
    //保存缩略图的地址.
    var saveUrl = '<%=request.getContextPath()%>/saveavatar.html';
    //保存摄象头白摄图片的地址.
    var cameraPostUrl = '<%=request.getContextPath()%>/camera.html';
    //头像编辑器flash的地址.
    var editorFlaPath = 'AvatarEditor.swf';
    //Download by http://www.codefans.net
    function useCamera()
    {
      var content = '<embed height="464" width="514" ';
      content +='flashvars="type=camera';
      content +='&postUrl='+cameraPostUrl+'?&radom=1';
      content +='&saveUrl='+saveUrl+'?radom=1" ';
      content +='pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" ';
      content +='allowscriptaccess="always" quality="high" ';
      content +='src="'+editorFlaPath+'"/>';
      document.getElementById('avatar_editor').innerHTML = content;
    }
    function buildAvatarEditor(pic_id,pic_path,post_type)
    {
      var content = '<embed height="464" width="514"'; 
      content+='flashvars="type='+post_type;
      content+='&photoUrl='+pic_path;
      content+='&photoId='+pic_id;
      content+='&postUrl='+cameraPostUrl+'?&radom=1';
      content+='&saveUrl='+saveUrl+'?radom=1"';
      content+=' pluginspage="http://www.macromedia.com/go/getflashplayer"';
      content+=' type="application/x-shockwave-flash"';
      content+=' allowscriptaccess="always" quality="high" src="'+editorFlaPath+'"/>';
      document.getElementById('avatar_editor').innerHTML = content;
    }
      /**
        * 提供给FLASH的接口 ： 没有摄像头时的回调方法
        */
       function noCamera(){
         alert("俺是小狗, 俺没有camare ：）");
       }
          
      /**
       * 提供给FLASH的接口：编辑头像保存成功后的回调方法
       */
      function avatarSaved(){
        alert('保存成功，哈哈');
        //window.location.href = '/profile.do';
      }
      
       /**
        * 提供给FLASH的接口：编辑头像保存失败的回调方法, msg 是失败信息，可以不返回给用户, 仅作调试使用.
        */
       function avatarError(msg){
         alert("上传失败了呀，哈哈");
       }

       function checkFile()
       {
         var path = document.getElementById('Filedata').value;
         var ext = getExt(path);
         var re = new RegExp("(^|\\s|,)" + ext + "($|\\s|,)", "ig");
          if(extensions != '' && (re.exec(extensions) == null || ext == '')) {
         alert('对不起，只能上传jpg, gif, png类型的图片');
         return false;
         }
         showLoading();
         return true;
       }

       function getExt(path) {
        return path.lastIndexOf('.') == -1 ? '' : path.substr(path.lastIndexOf('.') + 1, path.length).toLowerCase();
      }
              function  showLoading()
        {
          document.getElementById('loading_gif').style.visibility = 'visible';
        }
        function hideLoading()
        {
        document.getElementById('loading_gif').style.visibility = 'hidden';
        }
    </script>
  </div>
</div>

</body>

</html>